<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
$CI    = &get_instance();
function _pv( $k )
{
    global $CI;
    return $CI->input->post( $k );
}
function _uk( $n, $default = 0 )
{
    global $CI;
    return $CI->uri->segment( $n , $default ) ;
}
function _ruk($n, $default = 0)
{
    global $CI;
    return $CI->uri->rsegment( $n , $default ) ;
}
function _gc( $key )
{
    global $CI;
    return $CI->config->item( $key );
}
function _gs($key)
{
    global $CI;
    $CI->load->library('session');
	return $CI->session->userdata($key);
}
function _json($data)
{
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); 
	header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); 
	header("Cache-Control: no-cache, must-revalidate" ); 
	header("Pragma: no-cache" );
	header("Content-type: text/x-json");
	die(json_encode($data));
}
function showpage($data = array() , $module = '' , $isshow = true)
{
	global $CI;
	$content	= $CI->load->view('header', $data['header'], true);
	$content	.= $CI->load->view($module, $data['body'], true);
	$content	.= $CI->load->view('footer', '', true);
	if ($isshow == true)
	{
		echo $content;
	}
	else
	{
		return $content;
	}
}
function getMenu()
{
	global $CI;
	$CI->load->view('customers/agent_menu');
}
function getAdminMenu()
{
	global $CI;
	$CI->load->view('admin/admin_menu');
}
function getStatus($flag = 0)
{
	switch ($flag) 
	{
		case 1:
			return '审核通过';
			break;
		case 2:
			return '正式订单';
		case -1:
			return '审核未通过';
		default:
			return '审核中';
			break;
	}
}
function getAgentStatus($agentStatus	= 0)
{
	switch ($agentStatus)
	{
		case -1:
			return '被禁止';
			break;
		default	:
			return '正常';
			break;
	}
}
function genPageLinkNav($total_rows = 0, $base_url = '', $uri_segment = 3, $page_num = 0, $num_links = 5)
{
    global $CI;
    $CI->load->library('pagination');
    if ($page_num <= 0)
    {
        $page_num    = _gc('pagenum');
    }
    $pg['per_page'] = $page_num;

    $pg['base_url'] = _gc('base_url') . $base_url ;
    $pg['total_rows'] = $total_rows;

    $pg['uri_segment'] = $uri_segment;
    $pg['num_links'] = $num_links;
    $pg['full_tag_open'] = '<div class="pagination">';
    $pg['full_tag_close'] = '</div>';
    $pg['first_link'] = '首页';
    $pg['first_tag_open'] = '<span class="number" style="cursor: pointer;">';
    $pg['first_tag_close'] = '</span>';
    $pg['last_link'] = '末页';
    $pg['last_tag_open'] =  '<span class="number" style="cursor: pointer;">';
    $pg['last_tag_close'] = '</span>';
    $pg['next_link'] = '下一页';
    $pg['next_tag_open'] =  '<span class="number" style="cursor: pointer;">';
    $pg['next_tag_close'] = '</span>';
    $pg['prev_link'] = '上一页';
    $pg['prev_tag_open'] =  '<span class="number" style="cursor: pointer;">';
    $pg['prev_tag_close'] = '</span>';
    $pg['cur_tag_open'] = '<span class="number current">';
    $pg['cur_tag_close'] = '</span>';
    $pg['num_tag_open'] =  '<span class="number" style="cursor: pointer;">';
    $pg['num_tag_close'] = '</span>';
    $CI->pagination->initialize($pg);
    return $CI->pagination->create_links();
}
function getAgentNickNameById($id)
{
	global $CI;
	$CI->db->from('agent');
	$CI->db->where(array('id'=>$id));
	$result	= $CI->db->get();
	$row	= $result->row();
	return $row->nickname;
}